<?php
 session_start();
 include("include/session.php");
 include("include/common.php");
 include("include/db.php");
 
 $trainer_id = $_REQUEST['trainer_id'];
 

 

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?=TITLE_WEBSITE?></title>
<link href="css/c_energy.css" rel="stylesheet" type="text/css" />
<link href="css/logo.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" media="screen" type="text/css" href="css/layout.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/datepicker.js"></script>
<script type="text/javascript" src="js/eye.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript">
</script>
<style type="text/css">
<!--
.style4 {
	font-size: 22px;
	font-weight: bold;
}
.style6 {color: #999999}
-->
</style>
</head>
<script>
function validation(){

	var message = '';
	if(document.getElementById("trainer").value == ""){
		message += 'Please enter course category\n';
	}
	if(message != ""){
		alert(message);
		return false;
	}
}
</script>
<body>

    <table width="990" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="3" align="left" valign="top" ><? require("header.php");?></td>
</tr>
  <tr>
    <td align="center" >
	<table width="99%" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="3" align="center" valign="top">&nbsp;</td>
      </tr>
       <tr bgcolor="#FAFAFA">
        <td colspan="0" align="left" valign="top" >
		   <table width="96%" cellspacing="0" cellpadding="0">
		    <tr>
		      <td width="2%" align="left" valign="top" style="padding-left:15px" ><? require("left.php");?></td>
		      <td width="94%"  valign="top" style="padding-left:15px" >
			  <form name="signform" action="" method="post" enctype="multipart/form-data" id="signform" onsubmit="return validation();" >
			    <table id="signInTbl" width="719" cellspacing="0" cellpadding="0" style="border:solid #cccccc 1px">
                  <tr>
                    <td colspan="2" align="left" bgcolor="#373737" class="loc_search_found_term"  style="border-bottom:solid #cccccc 1px">Course Assignment</td>
                  </tr>

                 <tr height="30">
                    <td width="249" align="left" style="padding-left:15px">Trainer </td>
                    <td width="466" align="left">
                    	<select id="trainer" name="trainer" onchange="window.location.href='addRating.php?trainer_id='+this.value">
                        	<option value="" >Select</option>
                        	<?php
                       		 $sqlCourses = mysql_query("SELECT user_id,email,first_name,mobile FROM software_user as SU 
																INNER JOIN software_user_courses as SUC
																	ON SU.id = SUC.user_id
																WHERE SUC.user_type = 'Trainer' AND SU.active = 'Y' group by email");
                        	 while($resCourses = mysql_fetch_array($sqlCourses)){
                        	?>
                        	<option value="<?=$resCourses["user_id"]?>" <?=($trainer_id == $resCourses["user_id"] ? 'selected=selected' : '')?> ><?=$resCourses["first_name"]?></option>
                        	<?php		
                        	}
                        	?>
                        </select>
                    
                    </td>
                </tr>
                <tr>
                	<td colspan="2"  align="center">
                    	<table width="90%">
                        	<tr bgcolor="#000000" >
                            	<td style="color:#FFF">Course</td>
                                <td style="color:#FFF">Course Id</td>
                                <td style="color:#FFF">Student</td>
                                <td style="color:#FFF">Rating</td>
                            </tr>
                    <?php
                     $sqlQuery = mysql_query("SELECT su.first_name,courses_id,course,trainer_rating,trainer_id 
					 											from software_users_courses_assign as suca 
																inner join software_user as su ON suca.user_id = su.Id 
																where trainer_id = '$trainer_id'");
						 while($resQuery = mysql_fetch_array($sqlQuery)){
					?>
					<tr height="30">
                		<td><?php echo $resQuery["course"] ?></td>
                        <td><?php echo $resQuery["courses_id"] ?></td>
                        <td><?php echo $resQuery["first_name"] ?></td>
                        <td><?php $rating = intval($resQuery["trainer_rating"]);
									$trating += $rating; 
								 if($rating > 0){
									 $total++;
									  for($i = 1;$i <= $rating ; $i++ )
									  {
							?>
									<img src="../images/rateing.png"  width="15" />&nbsp;
							<?php
									  }
								  }
						
						 ?></td>
                	</tr>
					<?php		 
						 }
						 if($total > 0){
					?>
                    <tr bgcolor="#333333" height="30" >
                    	<td colspan="4" style="color:#FFFFFF; font-weight:bold" >&nbsp;<strong>Overall Rating </strong>:&nbsp;
						
							<?php 
								$finalRating = ceil($trating/$total);
								 if($finalRating > 0){
									 $total++;
									  for($i = 1;$i <= $finalRating ; $i++ )
									  {
							?>
									<img src="../images/rateing.png"  width="15" />&nbsp;
							<?php
									  }
								  }	
								
							?></td>
                    </tr>
                    <?php
						 }else{
							 
					?>
                    	<tr bgcolor="#FF8080"  height="30">
                        	<td colspan="5" style="color:#FFFFFF;">&nbsp;Sorry,No Rating Available</td>
                        </tr>
                    <?php
						 }
					?>
                    </table>
                    </td>
                    </tr>
                   <tr  height="30">
                    <td width="249"  style="padding-left:15px" colspan="2" align="center"><input class="cls_button" type="submit" id="submit" name="submit" value="Submit"  /></td>
                  </tr>
                </table>
			    <ul class="site_nav_menu_buttons">
			      <li class="no_menu_li"><span><a href="courses.php">&nbsp;Back to Courses </a></span></li>
			      </ul>
			    <p>&nbsp;</p>
			  </form>			  </td>
            </tr>
	        </table></td>
        </tr>
      <tr bgcolor="#FAFAFA">
        <td width="800" align="center" valign="top">&nbsp;</td>
        <td width="100" colspan="2">&nbsp;</td>
      </tr>
	    <tr bgcolor="#FAFAFA">
        <td width="800" align="center" valign="top">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>